//
//  ZhViewController.m
//  8.14下午作业
//
//  Created by 张洪海 on 15/8/14.
//  Copyright (c) 2015年 mohekeji. All rights reserved.
//

#import "ZhViewController.h"
#import "CellTableViewCell.h"
#import "zhhViewController.h"
#define IP 24
#define High 60
@interface ZhViewController ()<UIAlertViewDelegate>

@end

@implementation ZhViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self sanMu];
    NSLog(@"页面已经加载");
    _arr = @[
             @{
                 @"header's name":@"header's one",
                 @"footer's name":@"footer's one",
                 @"list":@[
                         @{
                             @"title":@"张洪海",
                             @"content":@"出生于黑龙江"
                             },
                         @{
                             @"title":@"张洪海",
                             @"content":@"故乡双鸭山"
                             }
                         ]
                 },
             @{
                 @"header's name":@"header's two",
                 @"footer's name":@"footer's two",
                 @"list":@[
                         @{
                             @"title":@"张洪海1",
                             @"content":@"出生于黑龙江1"
                             },
                         @{
                             @"title":@"张洪海1",
                             @"content":@"故乡双鸭山1"
                             }
                         ]
                 },
             @{
                 @"header's name":@"header's Three",
                 @"footer's name":@"footer's Three",
                 @"list":@[
                         @{
                             @"title":@"张洪海2",
                             @"content":@"出生于黑龙江2"
                             },
                         @{
                             @"title":@"张洪海2",
                             @"content":@"故乡双鸭山2"
                             }
                         ]
                 },
             @{
                 @"header's name":@"header's Four",
                 @"footer's name":@"footer's Four",
                 @"list":@[
                         @{
                             @"title":@"张洪海3",
                             @"content":@"出生于黑龙江3"
                             },
                         @{
                             @"title":@"张洪海3",
                             @"content":@"故乡双鸭山3"
                             }
                         ]
                 }
             ];
    // 建立存储永生字典
    [[NSUserDefaults standardUserDefaults ] setValue:@"123" forKey:@"用户名"];
    // 取出字典的值
    NSString* quZhi = [[NSUserDefaults standardUserDefaults]valueForKey:@"用户名"];
    // 删除字典的值
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"用户名"];
}

// 三目运算符
-(void)sanMu{
    int u =1234;
    int i = 2234;
    NSString* str =u > i? @"小于":@"大于";
}

//在section 中有多少个row.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSDictionary * dic = [_arr objectAtIndex:section];
    NSArray* arr = dic [@"list"];
    return arr.count;
}



- (CellTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString* string = @"CellTableViewCell";
    CellTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:string];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:string owner:self options:nil] lastObject];
    }
    NSDictionary * dic = [_arr objectAtIndex:indexPath.section];
    NSArray * arr = dic [@"list"];
    NSDictionary *dic1 = [arr objectAtIndex:indexPath.row];
    cell.loginLabel1.text = dic1[@"title"];
    cell.loginLabel2.text = dic1[@"content"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UIAlertView *ale = [[UIAlertView alloc]initWithTitle:@"提示" message:@"确定要进行跳转吗" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [ale show];
    zhhViewController * vc = [[zhhViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _arr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return High;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return High;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return High;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView* view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 60)];
    view.backgroundColor = [UIColor blueColor];
    UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(0 , 0 , 100, 50)];
    NSDictionary* dic = [_arr objectAtIndex:section];
    label.text = dic[@"header's name"];
    [view addSubview:label];
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView* view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 60)];
    view.backgroundColor = [UIColor orangeColor];
    UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(0 , 0 , 100, 50)];
    NSDictionary* dic = [_arr objectAtIndex:section];
    label.text = dic[@"footer's name"];
    [view addSubview:label];
    return view;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSLog(@"页面将要出现");
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    NSLog(@"页面已经出现");
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    NSLog(@"页面将要消失");
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    NSLog(@"页面已经消失");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        NSLog(@"取消");
    }else{
        NSLog(@"确定");
    }
}

@end
